home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / BasePaneEditor.inc < prev    next >
Text File  |  1997-07-27  |  6KB  |  223 lines

  1. /*
  2.  *  File:       BasePaneEditor.inc
  3.  *  Summary:       Abstract base class for view's that edit pane objects.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->    10/15/96    JDJ        Created
  12.  */
  13.  
  14. #include <ZAutoPtr.h>
  15.  
  16. #include <ZMultipleUndoableCommand.h>
  17. #include <ZWindow.h>
  18.  
  19.  
  20. // ===================================================================================
  21. //    class CBaseEditPaneCommand
  22. // ===================================================================================
  23.  
  24. //---------------------------------------------------------------
  25. //
  26. // CBaseEditPaneCommand::~CBaseEditPaneCommand
  27. //
  28. //---------------------------------------------------------------
  29. template <class PANE, class PANEINFO>
  30. CBaseEditPaneCommand<PANE, PANEINFO>::~CBaseEditPaneCommand()
  31. {
  32. }
  33.  
  34.  
  35. //---------------------------------------------------------------
  36. //
  37. // CBaseEditPaneCommand::CBaseEditPaneCommand
  38. //
  39. //---------------------------------------------------------------
  40. template <class PANE, class PANEINFO>
  41. CBaseEditPaneCommand<PANE, PANEINFO>::CBaseEditPaneCommand(PANE* pane, const PANEINFO& oldInfo, const PANEINFO& newInfo) : mPane(pane)
  42. {
  43.     ASSERT(pane != nil);
  44.         
  45.     mOldInfo = oldInfo;
  46.     mNewInfo = newInfo;
  47.  
  48.     TWindow* window = dynamic_cast<TWindow*>(mPane->GetTopView());
  49.     if (window != nil)
  50.         mContext = window->GetUndoContext();
  51.     else
  52.         mContext = nil;
  53.     mDelete  = mContext == nil;
  54. }
  55.  
  56.  
  57. //---------------------------------------------------------------
  58. //
  59. // CBaseEditPaneCommand::GetText
  60. //
  61. //---------------------------------------------------------------
  62. template <class PANE, class PANEINFO>
  63. string CBaseEditPaneCommand<PANE, PANEINFO>::GetText() const
  64. {
  65.     return "";                                // should be inside a transaction
  66. }
  67.  
  68.  
  69. //---------------------------------------------------------------
  70. //
  71. // CBaseEditPaneCommand::IsValid
  72. //
  73. //---------------------------------------------------------------
  74. template <class PANE, class PANEINFO>
  75. bool CBaseEditPaneCommand<PANE, PANEINFO>::IsValid() const
  76. {
  77.     return mPane.TargetExists();
  78. }
  79.  
  80.  
  81. //---------------------------------------------------------------
  82. //
  83. // CBaseEditPaneCommand::OnDo
  84. //
  85. //---------------------------------------------------------------
  86. template <class PANE, class PANEINFO>
  87. void CBaseEditPaneCommand<PANE, PANEINFO>::OnDo()
  88. {
  89.     this->UpdatePane(mNewInfo);
  90. }
  91.  
  92.  
  93. //---------------------------------------------------------------
  94. //
  95. // CBaseEditPaneCommand::OnUndo
  96. //
  97. //---------------------------------------------------------------
  98. template <class PANE, class PANEINFO>
  99. void CBaseEditPaneCommand<PANE, PANEINFO>::OnUndo()
  100. {
  101.     this->UpdatePane(mOldInfo);
  102. }
  103.  
  104.  
  105. //---------------------------------------------------------------
  106. //
  107. // CBaseEditPaneCommand::OnRedo
  108. //
  109. //---------------------------------------------------------------
  110. template <class PANE, class PANEINFO>
  111. void CBaseEditPaneCommand<PANE, PANEINFO>::OnRedo()
  112. {
  113.     this->UpdatePane(mNewInfo);
  114. }
  115.  
  116. #pragma mark -
  117.  
  118. // ===================================================================================
  119. //    CBasePaneEditor
  120. // ===================================================================================
  121.  
  122. //---------------------------------------------------------------
  123. //
  124. // CBasePaneEditor::~CBasePaneEditor
  125. //
  126. //---------------------------------------------------------------
  127. template <class PANE, class PANEINFO, class EDITCOMMAND>
  128. CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::~CBasePaneEditor()
  129. {
  130. }
  131.  
  132.  
  133. //---------------------------------------------------------------
  134. //
  135. // CBasePaneEditor::CBasePaneEditor
  136. //
  137. //---------------------------------------------------------------
  138. template <class PANE, class PANEINFO, class EDITCOMMAND>
  139. CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::CBasePaneEditor(TView* superView) : CRootPaneEditor(superView)
  140. {
  141.     mPane = nil;
  142. }
  143.  
  144.  
  145. //---------------------------------------------------------------
  146. //
  147. // CBasePaneEditor::SetPane
  148. //
  149. //---------------------------------------------------------------
  150. template <class PANE, class PANEINFO, class EDITCOMMAND>
  151. void CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::SetPane(TPane* pane)
  152. {
  153.     ASSERT(pane != nil);
  154.     ASSERT(mPane == nil);
  155.     
  156.     mPane = dynamic_cast<PANE*>(pane);
  157.     ASSERT(mPane != nil);
  158.     
  159.     mOldInfo = mPane->GetInfo();
  160.         
  161.     this->SetEditorInfo(mOldInfo);
  162. }
  163.  
  164.  
  165. //---------------------------------------------------------------
  166. //
  167. // CBasePaneEditor::Apply
  168. //
  169. //---------------------------------------------------------------
  170. template <class PANE, class PANEINFO, class EDITCOMMAND>
  171. void CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::Apply()
  172. {
  173.     PANEINFO info = this->GetEditorInfo();
  174.     
  175.     this->SetPaneInfo(info);
  176. }
  177.  
  178.  
  179. //---------------------------------------------------------------
  180. //
  181. // CBasePaneEditor::Commit
  182. //
  183. //---------------------------------------------------------------
  184. template <class PANE, class PANEINFO, class EDITCOMMAND>
  185. void CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::Commit(TMultipleUndoableCommand* command)
  186. {
  187.     PANEINFO newInfo = this->GetEditorInfo();
  188.  
  189.     command->AddCommand(new EDITCOMMAND(mPane, mOldInfo, newInfo));
  190. }
  191.  
  192.  
  193. //---------------------------------------------------------------
  194. //
  195. // CBasePaneEditor::Revert
  196. //
  197. //---------------------------------------------------------------
  198. template <class PANE, class PANEINFO, class EDITCOMMAND>
  199. void CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::Revert()
  200. {
  201.     this->SetEditorInfo(mOldInfo);
  202.     this->SetPaneInfo(mOldInfo);
  203. }
  204.  
  205.  
  206. //---------------------------------------------------------------
  207. //
  208. // CBasePaneEditor::SetPaneInfo
  209. //
  210. //---------------------------------------------------------------
  211. template <class PANE, class PANEINFO, class EDITCOMMAND>
  212. void CBasePaneEditor<PANE, PANEINFO, EDITCOMMAND>::SetPaneInfo(const PANEINFO& info)
  213. {
  214.     TAutoPtr<EDITCOMMAND> command(new EDITCOMMAND(mPane, mOldInfo, info));
  215.  
  216.     command->UpdatePane(info);        
  217. }
  218.  
  219.  
  220.  
  221.  
  222.  
  223.